package tags;

import dao.tro.Country;

import javax.servlet.ServletException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;

public class InsertSingleCountry extends TagSupport {
    private Country country;

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    @Override
    public void release() {
        setCountry(null);
        super.release();
    }

    @Override
    public int doStartTag() {
        return EVAL_BODY_INCLUDE;
    }

    @Override
    public int doEndTag() throws JspException {
        pageContext.setAttribute("singleCountry", country, PageContext.REQUEST_SCOPE);
        try {
            pageContext.include("../Templates/Country.jsp");
        } catch (ServletException | IOException e) {
            throw new JspException();
        }
        return EVAL_PAGE;
    }
}
